package com.zzptc.zzsgz.bdsjws.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.zzptc.zzsgz.bdsjws.MyApplication;
import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.activities.Family_Activity;
import com.zzptc.zzsgz.bdsjws.vo.BBX;

import java.util.List;

/**
 * Created by Administrator on 2017/5/24 024 .
 */

public class BBX_Adapter extends RecyclerView.Adapter<BBX_Adapter.ViewHolder> {
    private List<BBX> list;
    private View itemView;

    public BBX_Adapter(List<BBX> data){
        this.list=data;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{

        private TextView textView;
        private ImageView imageView;

        public ViewHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.text_item);
            imageView = (ImageView) itemView.findViewById(R.id.img_item);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, final int viewType) {
        itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.recyclerview_item,parent,false);
        BBX_Adapter.ViewHolder viewHolder = new BBX_Adapter.ViewHolder(itemView);

        return viewHolder;

    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        BBX bbx=list.get(position);
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                switch (position){
                    case 6:
                        Intent intent=new Intent(MyApplication.getContext(), Family_Activity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                        MyApplication.getContext().startActivity(intent);
                        break;
                    case 0:
                        Toast.makeText(MyApplication.getContext(), "nnnn", Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        });
        holder.imageView.setImageDrawable(getBBXIcon(bbx.getIcon()));
        holder.textView.setText(bbx.getUsername());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public Drawable getBBXIcon(String Icon){
        Context context= MyApplication.getContext();
        int id=context.getResources().getIdentifier(Icon,"mipmap",context.getPackageName());

        return ContextCompat.getDrawable(context,id);
    }
}
